import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/3/6 23:41
 */

public class Solution {
    public int[] smallestK(int[] arr, int k){
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            queue.offer(arr[i]);
        }
        for (int i = k; i < arr.length; i++) {
            int val = queue.peek();
            if(val > arr[i]){
                queue.poll();
                queue.offer(arr[i]);
            }
        }
        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = queue.poll();
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = in.nextInt();
            }
            int k = in.nextInt();
            Solution solution = new Solution();
            int[] ret = solution.smallestK(arr,k);
            System.out.println(Arrays.toString(ret));
        }
    }
}
